package com.hopu.dy.controller;

import com.hopu.dy.entity.R;
import com.hopu.dy.pojo.GongNeng;
import com.hopu.dy.service.IGongNengService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("gongneng")
public class GongNengController {
    @Resource
    private IGongNengService gongNengService;

    // 获取功能数据
    @GetMapping("/{shipinId}")
    public R getGongNeng(@PathVariable long shipinId) {
        GongNeng gongNeng = gongNengService.getByShipinId(shipinId);
        return gongNeng != null ? R.ok(gongNeng) : R.err("数据不存在");
    }

    // 点赞
    @PostMapping("/love/{shipinId}")
    public R love(@PathVariable long shipinId) {
        boolean result = gongNengService.updateLoveNumber(shipinId);
        return result ? R.ok("点赞成功") : R.err("点赞失败");
    }

    // 评论
    @PostMapping("/pinglun/{shipinId}")
    public R pinglun(@PathVariable long shipinId) {
        boolean result = gongNengService.updatePinglunNumber(shipinId);
        return result ? R.ok("评论成功") : R.err("评论失败");
    }

    // 转发
    @PostMapping("/zhuanfa/{shipinId}")
    public R zhuanfa(@PathVariable long shipinId) {
        boolean result = gongNengService.updateZhuanfaNumber(shipinId);
        return result ? R.ok("转发成功") : R.err("转发失败");
    }

    // 收藏
    @PostMapping("/shoucang/{shipinId}")
    public R shoucang(@PathVariable long shipinId) {
        boolean result = gongNengService.updateShoucangNumber(shipinId);
        return result ? R.ok("收藏成功") : R.err("收藏失败");
    }
}